<?php

namespace Database\Seeders;

use App\Models\Event;
use App\Models\Order;
use App\Models\User;
use App\Models\Venue;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // 生成10个用户
        $users = User::factory(10)->create();
        
        // 生成5个场馆
        $venues = Venue::factory(5)->create();
        
        // 生成15个事件
        $events = Event::factory(15)->create();
        
        // 为每个用户生成2-5个订单
        $users->each(function ($user) use ($events) {
            $orderCount = rand(2, 5);
            for ($i = 0; $i < $orderCount; $i++) {
                $event = $events->random();
                Order::factory()->create([
                    'user_id' => $user->id,
                    'event_id' => $event->id,
                ]);
            }
        });
    }
}
